﻿<UserControl x:Class="Convertor.ManagePluginControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sm="clr-namespace:Wpf.CommonTools.SystemExtension;assembly=Wpf.CommonTools"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Convertor"
             xmlns:interf="clr-namespace:Convertor.Interface;assembly=Convertor.Interface"
             mc:Ignorable="d" 
             d:DesignHeight="300"
             Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <local:PluginIconConverter x:Key="PluginIconConverter"/>
        <local:AllPluginToNamesConverter x:Key="AllPluginToNamesConverter"/>
        <local:PuglinNameConverter x:Key="PuglinNameConverter"/>
        <local:PluginTypesConverter x:Key="PluginTypesConverter"/>
        <local:ControlSizeConverter x:Key="ControlSizeConverter"/>
    </UserControl.Resources>
    <Grid x:Name="GridPlugin" MinWidth="400">
        <Grid.RowDefinitions>
            <RowDefinition Height="35"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="{Binding Source={x:Static local:Config.GlobalConfig}, Path=ManagePluginHorizontalChange, Converter={StaticResource ControlSizeConverter}}" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="10"/>
            </Grid.ColumnDefinitions>
            <AdornerDecorator>
                <Border Style="{StaticResource BorderStyle}" Padding="0,5,0,5">
                    <ListBox ToolTip="{DynamicResource lstAllPluginTooTip}"
                     Style="{StaticResource NoneStyle}" Grid.Column="0" 
                     PreviewMouseLeftButtonDown="lstPlugin_PreviewMouseLeftButtonDown">
                        <ListBox.ItemsSource>
                            <MultiBinding  Converter="{StaticResource AllPluginToNamesConverter}" >
                                <Binding Source="{x:Static local:Config.GlobalConfig}" Path="AllPlugins"/>
                                <Binding ElementName="cbAllPluginTypes" Path="SelectedItem"/>
                                <Binding Source="{x:Static local:Config.GlobalConfig}" Path="DisabledPlugins"/>
                            </MultiBinding>
                        </ListBox.ItemsSource>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" Margin="1">
                                    <Image Source="{Binding Path=Name, Converter={StaticResource PluginIconConverter}}" Width="16" Margin="0,0,3,0"/>
                                    <TextBlock Text="{Binding Path=Name}" ToolTip="{Binding Path=Description}" />
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        <sm:WatermarkService.Titlemark>
                            <TextBlock Text="{DynamicResource All_Plugin_List}" TextAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,20,20"/>
                        </sm:WatermarkService.Titlemark>
                    </ListBox>
                </Border>
            </AdornerDecorator>
            <Image Source="Images/Up.png" Width="10" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
                <Image.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="90"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </Image.RenderTransform>
            </Image>
        </Grid>
        <GridSplitter VerticalAlignment="Stretch" ResizeDirection="Columns" Opacity="0" Width="10" Grid.Row="1" DragCompleted="GridSplitter_DragCompleted"/>
        <DockPanel LastChildFill="True" Grid.Column="2" Grid.Row="1">
            <AdornerDecorator>
                <Border Style="{StaticResource BorderStyle}" Padding="0,5,0,5">
                    <TreeView x:Name="tvPlugins"
                        DockPanel.Dock="Top"
                        Style="{StaticResource NoneStyle}"
                        ItemsSource="{Binding Source={x:Static local:Config.CurrentPlugin}, Path=SelectedPlugins}"
                        PreviewMouseLeftButtonDown="tvPlugins_PreviewMouseLeftButtonDown"
                        PreviewMouseRightButtonUp="tvPlugins_PreviewMouseRightButtonDown" 
                        ContextMenuOpening="tvPlugins_ContextMenuOpening"
                        SelectedItemChanged="tvPlugins_SelectedItemChanged"
                        Drop="tvPlugins_Drop"
                        KeyUp="tvPlugins_KeyUp"
                        AllowDrop="True">
                        <TreeView.ItemContainerStyle>
                            <Style TargetType="{x:Type TreeViewItem}">
                                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                                <Setter Property="FontWeight" Value="Normal" />
                                <Style.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter Property="FontWeight" Value="Normal" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </TreeView.ItemContainerStyle>
                        <TreeView.ItemTemplate>
                            <HierarchicalDataTemplate ItemsSource="{Binding ChildPlugins}" DataType="{x:Type interf:IPluginItem}">
                                <WrapPanel ToolTip="{Binding Config.ToolTip}">
                                    <TextBlock Text="{Binding Path, Converter={StaticResource PuglinNameConverter}}" HorizontalAlignment="Stretch" />
                                    <TextBlock Text="{Binding Memo, Converter={StaticResource StringToLimitConverter}, ConverterParameter=10}" HorizontalAlignment="Stretch" Margin="5,0,0,0" Foreground="Gray"/>
                                </WrapPanel>
                            </HierarchicalDataTemplate>
                        </TreeView.ItemTemplate>
                        <TreeView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Name="menuItemTConfig" Header="{DynamicResource PuglinSetting}" Click="menuItem_Config_Click">
                                    <MenuItem.Icon>
                                        <Image Source="Images/Setting.png"></Image>
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Name="menuItemTRunTo" Header="{DynamicResource RunToHere}" Click="menuItem_RunTo_Click"/>
                                <MenuItem Name="menuItemTMoveTo" Header="{DynamicResource MovePluginTo}" Click="menuItem_MoveTo_Click"/>
                                <MenuItem Name="menuItemCopy" Header="{DynamicResource Copy}" Click="menuItem_Copy_Click">
                                    <MenuItem.Icon>
                                        <Image Source="Images/Copy.gif" Width="15"></Image>
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Name="menuItemPaste" Header="{DynamicResource Paste}" Click="menuItem_Paste_Click">
                                    <MenuItem.Icon>
                                        <Image Source="Images/Paste.png" Width="15"></Image>
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Name="menuItemTDelete" Header="{DynamicResource Delete}" Click="menuItem_Delete_Click">
                                    <MenuItem.Icon>
                                        <Image Source="Images/Delete.png" Width="15"></Image>
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Name="menuItemTClear" Header="{DynamicResource Clear}" Click="menuItem_Clear_Click"/>
                            </ContextMenu>
                        </TreeView.ContextMenu>
                        <sm:WatermarkService.Titlemark>
                            <TextBlock Text="{DynamicResource Selected_Plugin_List}" TextAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,20,20"/>
                        </sm:WatermarkService.Titlemark>
                    </TreeView>
                </Border>
            </AdornerDecorator>
        </DockPanel>
        <WrapPanel Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Left" VerticalAlignment="Center" >
            <ComboBox x:Name="cbAllPluginTypes" Margin="5,0,0,0"
                      SelectedIndex="{Binding Source={x:Static local:Config.GlobalConfig}, Path=PluginType, UpdateSourceTrigger=LostFocus}"
                      Width="120" Padding="15,3,15,3">
                <ComboBox.ItemsSource>
                    <MultiBinding Converter="{StaticResource PluginTypesConverter}" Mode="OneWay">
                        <Binding Source="{x:Static local:Config.GlobalConfig}" Path="AllPlugins"/>
                        <Binding Source="{x:Static local:Config.GlobalConfig}" Path="DisabledPlugins"/>
                    </MultiBinding>
                </ComboBox.ItemsSource>
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Margin="1">
                            <Image Source="{Binding Path=., Converter={StaticResource PluginIconConverter}}" Width="16" Margin="0,0,3,0"/>
                            <TextBlock Text="{Binding Path=.}" />
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
        </WrapPanel>
    </Grid>
</UserControl>
